package cn.com.xy.sms.sdk.ui.popu.part;

import java.util.Map;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.part.UIPart;
import cn.com.xy.sms.sdk.ui.popu.util.ChannelContentUtil;
import cn.com.xy.sms.sdk.ui.popu.util.ThemeUtil;
import cn.com.xy.sms.sdk.ui.popu.widget.SmartisanosTypeface;
import cn.com.xy.sms.sdk.util.StringUtils;

@SuppressLint("ResourceAsColor")
public class BubbleGeneralTwoTextBody extends UIPart {

    private TextView mTitleTextView = null;
    private TextView mContentTextView = null;
    private View mSpliteView;
    private static final String TABLE_KEY = "duoqu_table_data_horiz";

    public BubbleGeneralTwoTextBody(Activity context, BusinessSmsMessage message, XyCallBack callback, int layoutId,
            ViewGroup root, int partId) {
        super(context, message, callback, layoutId, root, partId);
    }

    @Override
    public void initUi() {
        mTitleTextView = (TextView) mView.findViewById(R.id.duoqu_bubble_generalone_title);
        mContentTextView = (TextView) mView.findViewById(R.id.duoqu_bubble_generalone_content);
        mSpliteView = mView.findViewById(R.id.duoqu_bubble_generalone_splite_view);
    }

    @Override
    public void setContent(BusinessSmsMessage message, boolean isRebind) throws Exception {
        this.mMessage = message;
        if (message == null) {
            return;
        }
        String contStr = (String) mMessage.getValue("m_by_text_d_1");
        if(StringUtils.isNull(contStr)){
            mView.setVisibility(View.GONE);
            return ;
        }else{
            mView.setVisibility(View.VISIBLE);
        }
        setViewStyle(mMessage);
        String titleStr = (String) mMessage.getValue("m_by_text_u_1");
        /* SMARTISAN-277 zhaoxiachao 20161202 start */
        String flag=(String) mMessage.getValue("mark");
        if(StringUtils.isNull(flag)){
            mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, ChannelContentUtil.needUpdateContTextSize(contStr));
        }else {
            mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, ChannelContentUtil.needEnglishUpdateTextSize(contStr));
        }
        /* SMARTISAN-277 zhaoxiachao 20161202 end */
        if(contStr.contains("\n")){
            mContentTextView.setGravity(Gravity.CENTER);
        }else{
            mContentTextView.setGravity(Gravity.CENTER_VERTICAL);
        }
        
        
        ChannelContentUtil.setText(mTitleTextView, titleStr, "");
        ChannelContentUtil.setText(mContentTextView, contStr, "");

        if(mMessage.getTableDataSize(TABLE_KEY) > 0){
            mSpliteView.setVisibility(View.VISIBLE);
        }else{
            mSpliteView.setVisibility(View.INVISIBLE);
        }
        
        /* SMARTISAN-419 zhaoxiachao 20170217 start */
        if(SmartisanosTypeface.CLOCK != null){
            mContentTextView.setTypeface(SmartisanosTypeface.CLOCK);
        }
        /* SMARTISAN-419 zhaoxiachao 20170217 end */
    }
    
    /**
     * 设置View的样式
     * 
     * @param message
     */
    private void setViewStyle(BusinessSmsMessage message) {
        // TODO Auto-generated method stub
        ThemeUtil.setViewBg(mContext, mView, "", R.drawable.duoqu_v_by_bg_1);
        ThemeUtil.setTextColor(mContext, mTitleTextView, (String) mMessage.getValue("v_by_text_u_1"),
                R.color.duoqu_theme_color_5010);
        ThemeUtil.setTextColor(mContext, mContentTextView, (String) mMessage.getValue("v_by_text_d_1"),
                R.color.duoqu_theme_color_3010);
    }

    @Override
    public void changeData(Map<String, Object> param) {
        /* SMARTISAN-261 zhaoxiachao 20161129 start */
        if(param != null && !StringUtils.isNull(param.get(ChannelContentUtil.CHANGE_TRAIN)+"")){
            return;
        }
        /* SMARTISAN-261 zhaoxiachao 20161129 end */
    }
}
